package com.wql.study;
//package com.wql.study;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import javassist.ClassClassPath;
//import javassist.ClassPool;
//import javassist.CtClass;
//import javassist.CtMethod;
//import javassist.Modifier;
//import javassist.bytecode.CodeAttribute;
//import javassist.bytecode.LocalVariableAttribute;
//import javassist.bytecode.MethodInfo;
//
//import org.apache.commons.collections.CollectionUtils;
//import org.springframework.stereotype.Controller;
//import org.springframework.util.StringUtils;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import com.cool.app.annotation.ApiDescription;
//import com.cool.app.resultmsg.vo.ParamInfo;
//import com.cool.app.resultmsg.vo.RequestInfo;
//import com.cool.app.util.ApiUtils;
//import com.cool.app.util.JSONUtils;
//
///**
// * api测试类
// * 
// * @author wuqinglong
// */
//@Controller
//public class Controller extends BaseController {
//
//	private Map<String, List<RequestInfo>> getApiInfos() throws Exception {
//		List<Class<?>> setControllerClass = ApiUtils.getClasses("com.cool.app.controller");
//		List<String> ignoreController = Arrays.asList("com.cool.app.controller.Controller".split(" "));
//		List<String> allControllers = new ArrayList<String>();
//		if (CollectionUtils.isNotEmpty(setControllerClass)) {
//			for (Class<?> cls : setControllerClass) {
//				if (ignoreController.contains(cls.getName())) {
//					continue;
//				}
//				allControllers.add(cls.getName());
//			}
//		}
//		Map<String, List<RequestInfo>> result = new HashMap<String, List<RequestInfo>>();
//		ClassPool pool = ClassPool.getDefault();
//		pool.insertClassPath(new ClassClassPath(BaseController.class));
//		for (String className : allControllers) {
//			CtClass cc = pool.get(className);
//			Controller controllerMapping = (Controller) cc.getAnnotation(Controller.class);
//			if (null == controllerMapping) {
//				continue;
//			}
//			for (CtMethod cm : cc.getDeclaredMethods()) {
//				MethodInfo mi = cm.getMethodInfo();
//				RequestInfo requestinfo = new RequestInfo();
//				RequestMapping requestMapping = (RequestMapping) cm.getAnnotation(RequestMapping.class);
//				if (null == requestMapping) {
//					continue;
//				}
//				requestinfo.setUrl(controllerMapping.value() == null ? requestMapping.value()[0] + ".do" : controllerMapping.value() + requestMapping.value()[0] + ".do");
//				ApiDescription api = (ApiDescription) cm.getAnnotation(ApiDescription.class);
//				if (null != api) {
//					String title = api.title();
//					requestinfo.setTitle(StringUtils.isEmpty(title) ? requestMapping.value()[0] + ".do" : title);
//					String description = api.description();
//					requestinfo.setDesc(StringUtils.isEmpty(description) ? requestMapping.value()[0] + ".do" : description);
//					requestinfo.setGroup(api.group().equals("") ? requestinfo.getTitle() : api.group());
//				} else {
//					requestinfo.setTitle(mi.getName());
//					requestinfo.setDesc("");
//				}
//				CodeAttribute codeAttribute = mi.getCodeAttribute();
//				LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
//				if (cm.getParameterTypes().length > 0) {
//					requestinfo.setParams(new ArrayList<ParamInfo>());
//					String[] paramNames = new String[cm.getParameterTypes().length];
//					int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
//					for (int i = 0, j = paramNames.length; i < j; i++) {
//						ParamInfo pi = new ParamInfo();
//						pi.setName(attr.variableName(i + pos));
//						pi.setType(cm.getParameterTypes()[i].getSimpleName());
//						requestinfo.getParams().add(pi);
//					}
//				}
//				requestinfo.setJson(JSONUtils.toJSON(requestinfo));
//				List<RequestInfo> list = result.get(requestinfo.getGroup());
//				list = (list == null ? new ArrayList<RequestInfo>() : list);
//				list.add(requestinfo);
//				result.put(requestinfo.getGroup(), list);
//			}
//		}
//		return result;
//	}
//}